﻿/*
*   学员端考试历史页面
*/
// 主页内容 由于angular 独立域（又懒加载）所以这里不能再用 jisuStuApp 了 只能angular.module('jisuStuHome') 获取模块后加controller 这样才能懒加载成功
angular.module('jisuStuHome').controller('stuExamHistoryList', ['$scope', '$rootScope', '$timeout', 'StuRequestTrain', 'sysUserInfo', 'Msg', 'T', function ($scope, $rootScope, $timeout, ST, sysUserInfo, Msg, T) {
    // 初始化

    // 请求参数
    $scope.params = {
        pageIndex: 1,     // 当前页
        pageSize: 15,   // 当前页面条数
        userid: sysUserInfo.getuserinfo().user_ID   // 用户id
    }
	// 外部成绩请求参数
    $scope.eparams = {
        pageIndex: 1,     // 当前页
        pageSize: 15,   // 当前页面条数
        listCount: 0,
        userId: sysUserInfo.getuserinfo().user_ID   // 用户id
    }
	$scope.showTable = 1; //默认展示内部试卷
    //切换版块
    $scope.selTabList = function (id) {
        $scope.showTable = id;
        if (id == 2) {
            $scope.getExternalHistoryList();
        }
    }
    //外部试卷loading
    $scope.externalLoading = false;
    $scope.externalList = [];

    //外部成绩的加载更多
    $scope.nextGetExternalHistoryList = function () {
        // 判断是否在查询中
        if ($scope.externalLoading) {
            Msg.info("提示", "正在查询中...");
            return;
        }
        $scope.eparams.pageIndex += 1;
        $scope.getExternalHistoryList();
    }
    // 获取外部考试历史记录
    $scope.getExternalHistoryList = function () {
        // 判断是否在查询中
        if ($scope.examHistoryLoading) {
            Msg.info("提示", "正在查询中...");
            return;
        }
        $scope.externalLoading = true;
        // 发送请求
        ST.findUserScorePage($scope.eparams).then(function (response) {
            $scope.externalLoading = false;
            if (response.errorcode == "0") {
                //添加记录
                angular.forEach(response.datas, function (data, index) {
                    $scope.externalList.push(data);
                });
                $scope.eparams.listCount = response.numCount;
            } else {
                Msg.error("错误", "服务器异常");
            }
        }, function errorCallback() {
            $scope.externalLoading = false;
            console.log("连接服务器失败！");
        });
    }
    $scope.switchs = false; //未开启显示成绩（开启后不能进入查看历史试卷）
    //获取考试开关
    $scope.getSwitch = function () {
        $scope.examHistoryLoading = true;
        // 发送请求
        ST.getOrgSwitch({ switchs: "switchs_exam_display", "orgid": sysUserInfo.getuserinfo().organization_ID }).then(function (response) {
            $scope.examHistoryLoading = false;
            if (response.errorcode == "0") {
                if (response.data != undefined && response.data != null && response.data.is_switch != undefined && response.data.is_switch == 0) {
                    $scope.switchs = true;
                }
            } else {
                Msg.error("错误", "服务器异常");
            }
        }, function errorCallback() {
            $scope.stuUserinfoLoading = false;
            console.log("连接服务器失败！");
        });
    }
    $scope.getSwitch();
    // 记录总行数
    $scope.listCount = 0;
    // 加载中
    $scope.examHistoryLoading = false;
    // 历史记录的集合
    $scope.examHistoryList = [];
    // 查询下一页的记录
    $scope.nextGetExamHistoryList = function () {
        // 判断是否在查询中
        if ($scope.examHistoryLoading) {
            Msg.info("提示", "正在查询中...");
            return;
        }
        $scope.params.pageIndex += 1;
        $scope.getExamHistoryList();
    }
    // 获取考试历史记录
    $scope.getExamHistoryList = function () {
        // 判断是否在查询中
        if ($scope.examHistoryLoading) {
            Msg.info("提示", "正在查询中...");
            return;
        }
        $scope.examHistoryLoading = true;
        // 发送请求
        ST.historyPaper($scope.params).then(function (response) {
            $scope.examHistoryLoading = false;
            if (response.errorcode == "0") {
                //添加记录
                angular.forEach(response.datas, function (data, index) {
                    $scope.examHistoryList.push(data);
                });
                $scope.listCount = response.numCount;
            } else {
                Msg.error("错误", "服务器异常");
            }
        }, function errorCallback() {
            $scope.stuUserinfoLoading = false;
            console.log("连接服务器失败！");
        });
    }
    $scope.getExamHistoryList();

    // 打开连接
    $scope.openUrlLink = function (obj) {

        var item = obj.exampaper;
        if (item == undefined || item == null) {
            Msg.warning("该试卷已被删除!");
            return;
        }
        //随机卷
        if (item.paper_Random == "0") {
            $scope.commonUrl = $rootScope.fileurl + "/resources/exam/" + obj.paperId + "," + item.paperCount + "/" + ((obj.randomNum == undefined) ? 1 : obj.randomNum) + ".html?id=99&scoreId=" + obj.scoreId + "&userid=" + sysUserInfo.getuserinfo().user_ID + "&token=" + sysUserInfo.getuserinfotoken();
            //固定卷
        } else {
            $scope.commonUrl = $rootScope.fileurl + item.url + "?id=99&scoreId=" + obj.scoreId + "&userid=" + sysUserInfo.getuserinfo().user_ID + "&token=" + sysUserInfo.getuserinfotoken();
        }

        $timeout(function () { document.getElementById("commonHref").click(); }, 350); /// <reference path="stuexamhistory.js" />

    }
} ]);

